package com.tkjt.pms.modules.repos.controller;

import com.tkjt.pms.modules.repos.vo.*;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tkjt.pms.modules.repos.common.IndexInfoTreeParam;
import com.tkjt.pms.modules.repos.service.IndexRepoService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/pms/repos/indexRepo")
public class IndexRepoController {
    @Autowired
    private IndexRepoService indexRepoService;
    /**
     * *指标树-节点层级(指标层级)
     * *@return
     */
    @RequestMapping("indexTree")
    public Result<?> indexTree(@RequestBody IndexInfoTreeParam treeParam){
        try {
            return indexRepoService.indexTree(treeParam);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }
    /**
     * *指标树-节点删除(逻辑删除)
     * @return
     */
    @RequestMapping("delNode")
    public Result<?> delNode(@RequestBody IndexInfoTreeVO indexInfoTreeVO){
        try {
            return indexRepoService.delNode(indexInfoTreeVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }

    /**
     * *指指标树-节点新增(指标或数据项)
     * @return
     */
    @RequestMapping("addNode")
    public Result<?> addNode(@RequestBody IndexInfoTreeAddVO indexInfoTreeAddVO){
        try {
            return indexRepoService.addNode(indexInfoTreeAddVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }

    /**
     * *节点属性-查询
     * @return
     */
    @RequestMapping("queryAttrs")
    public Result<?> queryAttrs(@RequestBody IndexInfoTreeVO indexInfoTreeVO){
        try {
            return indexRepoService.queryAttrs(indexInfoTreeVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }

    /**
     * *节点属性-修改/保存
     * @return
     */
    @RequestMapping("modifyAttrs")
    public Result<?> modifyAttrs(@RequestBody IndexInfoAttrsAddVO indexInfoAttrsAddVO){
        try {
            return indexRepoService.modifyAttrs(indexInfoAttrsAddVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }

    /**
     * *节点属性-属性选项
     * @return
     */
    @RequestMapping("listAttrs")
    public Result<?> listAttrs(@RequestBody IndexInfoTreeVO indexInfoTreeVO){
        try {
            return indexRepoService.listAttrs(indexInfoTreeVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }

    /**
     * *节点排序
     * @return
     */
    @RequestMapping("orderIndexs")
    public Result<?> orderIndexs(@RequestBody IndexInfoTreeVO indexInfoTreeVO){
        try {
            return indexRepoService.orderIndexs(indexInfoTreeVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }

    /**
     * 规则库-列表详情
     * @param indexValueRuleVO
     * @return
     */
    @RequestMapping("indexRuleDatagrid")
    public Result<?> indexRuleDatagrid(@RequestBody IndexValueRuleVO indexValueRuleVO){
        try {
            return indexRepoService.indexRuleDatagrid(indexValueRuleVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }

    /**
     * 规则库-新增/修改-数据项日期标识
     * @param
     * @return
     */
    @RequestMapping("whichDataList")
    public Result<?> whichDataList(){
        try {
            return indexRepoService.whichDataList();
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }
    /**
     * 规则库-新增/修改-数据项目编码(模糊查询)
     * @param indexValueRuleVO
     * @return
     */
    @RequestMapping("searchIndexValue")
    public Result<?> searchIndexValue(@RequestBody IndexValueRuleVO indexValueRuleVO){
        try {
            return indexRepoService.searchIndexValue(indexValueRuleVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }

    /**
     * 规则库-新增/修改-保存单条
     * @param tkIndexValueRuleVO
     * @return
     */
    @RequestMapping("indexRuleSave")
    public Result<?> indexRuleSave(@RequestBody TkIndexValueRuleVO tkIndexValueRuleVO){
        try {
            return indexRepoService.indexRuleSave(tkIndexValueRuleVO);
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return Result.error("获取数据异常");
        }
    }
}
